package com.shuoyue.ycgk.ui.estimate;

import android.text.Html;
import android.text.TextUtils;

import androidx.annotation.Nullable;

import com.chad.library.adapter.base.BaseViewHolder;
import com.shuoyue.ycgk.R;
import com.shuoyue.ycgk.base.baseadapter.AppBaseQuickAdapter;
import com.shuoyue.ycgk.entity.Estimate;
import com.shuoyue.ycgk.utils.XDateUtils;

import java.util.List;

public class EstimateAdapter extends AppBaseQuickAdapter<Estimate> {
    public EstimateAdapter(@Nullable List<Estimate> data) {
        super(R.layout.item_estimate, data);
    }


    @Override
    protected void convert(BaseViewHolder helper, Estimate item) {
        helper.addOnClickListener(R.id.start);
        helper.setText(R.id.name, item.getTitle());
        helper.setText(R.id.begin_time, "估分时间: "
                + item.getStartTime()
                + "~"
                + item.getEndTime());
//        helper.setText(R.id.regist_num, item.getIsSign() == 1 ?
//                Html.fromHtml("<font color='#06A0DC'>" + item.getUnitName() + "--" + item.getPostName() + "</font>")
//                : Html.fromHtml(
//                "已有"
//                        +
//                        "<font color='#06A0DC'>" + item.getTotalPerson() + "</font>人报名"
//
//        ));
        helper.setText(R.id.regist_num, Html.fromHtml(
                "已有"
                        +
                        "<font color='#06A0DC'>" + item.getTotalPerson() + "</font>人报名"

        ));
        helper.setGone(R.id.regist_job, !TextUtils.isEmpty(item.getPostName()));
        helper.setText(R.id.regist_job, Html.fromHtml("<font color='#06A0DC'>" + item.getUnitName() + "--" + item.getPostName() + "</font>"));

        if (item.getIsSign() == 0) {
            if (item.getActionStatus() != 3) {
                helper.setText(R.id.start, "立即报名");
                helper.setBackgroundRes(R.id.start, R.drawable.button_bg_theme);
                helper.getView(R.id.start).setEnabled(true);
            } else {
                helper.setText(R.id.start, "已结束");
                helper.setBackgroundRes(R.id.start, R.drawable.button_bg_theme_unclickable);
                helper.getView(R.id.start).setEnabled(true);
            }

        } else if (item.getStatus() == 1) {
            //已交卷
            helper.setBackgroundRes(R.id.start, R.drawable.button_bg_orange);
            helper.getView(R.id.start).setEnabled(true);
            helper.setText(R.id.start, "查看排行");
        } else if (item.getActionStatus() == 1) {
            //未交卷的，如果action==2，进入考试，1显示倒计时
            helper.setBackgroundRes(R.id.start, R.drawable.button_bg_theme_unclickable);
            long now = System.currentTimeMillis();

            //已报名未开始
            long lastTimeLong = item.getLeftTime() - now;
//            if (lastTimeLong > 1000 * 60 * 60 * 24) {
//                helper.setText(R.id.start, "等待考试");
//
//            } else {
                String timeStr = XDateUtils.formatDDHHmm(lastTimeLong);
                helper.setText(R.id.start, "倒计时：" + timeStr);

//            }
        } else if (item.getActionStatus() == 2) {
            helper.setBackgroundRes(R.id.start, R.drawable.button_bg_theme);
            helper.setText(R.id.start, "进入考试");
        } else {
            helper.setBackgroundRes(R.id.start, R.drawable.button_bg_orange);
            helper.getView(R.id.start).setEnabled(true);
            helper.setText(R.id.start, "查看排行");
        }
    }
}
